package observer;

import java.util.ArrayList;
import java.util.List;
import java.util.Observer;

public class Subject {
    private List<MyObserver> observers = new ArrayList<>();
    private int state;

    public int getState() {
        return this.state;
    }

    public void setState(int state) {
        this.state = state;
        notifyAllObservers();
    }

    public void attach(MyObserver observer) {
        observers.add(observer);
    }

    public void notifyAllObservers() {
        for (MyObserver o : observers) {
            o.update();
        }
    }

}
